package com.hrm.houfei.dao.impl;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.hrm.houfei.dao.IMoneyInfoDAO;
import com.hrm.houfei.po.Moneyinfo;
import com.hrm.houfei.po.Userinfo;

/**
 * A data access object (DAO) providing persistence and search support for
 * Moneyinfo entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.hrm.houfei.po.Moneyinfo
 * @author MyEclipse Persistence Tools
 */

public class MoneyinfoDAO extends HibernateDaoSupport implements IMoneyInfoDAO {
	private static final Log log = LogFactory.getLog(MoneyinfoDAO.class);

	protected void initDao() {
		// do nothing
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hrm.houfei.dao.impl.IMoneyInfoDAO#save(com.hrm.houfei.po.Moneyinfo)
	 */
	public void save(Moneyinfo transientInstance) {
		log.debug("saving Moneyinfo instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	/**
	 * 分页查询薪酬标准单信息
	 * 
	 * @param criteria
	 *            标准查询
	 * @param start
	 *            索引
	 * @param limit
	 *            每页要显示的记录
	 * @return 当前页的所有记录
	 */
	public List<Moneyinfo> findByPage(DetachedCriteria criteria, int start,
			int limit) {
		HibernateTemplate ht = super.getHibernateTemplate();
		List<Moneyinfo> list = ht.findByCriteria(criteria, start, limit);
		return list;
	};

	/**
	 * 更新薪酬标准信息
	 * 
	 * @param Moneyinfo
	 *            Moneyinfo实体
	 */
	public void updateMoneyInfoByStandardId(Moneyinfo entity) {
		try {
			HibernateTemplate ht = super.getHibernateTemplate();
			ht.update(entity);
		} catch (RuntimeException re) {
			log.error("update failed", re);
			throw re;
		}

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hrm.houfei.dao.impl.IMoneyInfoDAO#delete(com.hrm.houfei.po.Moneyinfo)
	 */
	public void delete(Moneyinfo persistentInstance) {
		log.debug("deleting Moneyinfo instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hrm.houfei.dao.impl.IMoneyInfoDAO#findById(java.lang.Integer)
	 */
	public Moneyinfo findById(java.lang.Integer id) {
		log.debug("getting Moneyinfo instance with id: " + id);
		try {
			Moneyinfo instance = (Moneyinfo) getHibernateTemplate().get(
					Moneyinfo.class, id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hrm.houfei.dao.impl.IMoneyInfoDAO#findByExample(com.hrm.houfei.po.Moneyinfo)
	 */
	public List findByExample(Moneyinfo instance) {
		log.debug("finding Moneyinfo instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hrm.houfei.dao.impl.IMoneyInfoDAO#findByProperty(java.lang.String,
	 *      java.lang.Object)
	 */
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Moneyinfo instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Moneyinfo as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hrm.houfei.dao.impl.IMoneyInfoDAO#findAll()
	 */
	public List findAll() {
		log.debug("finding all Moneyinfo instances");
		try {
			String queryString = "from Moneyinfo";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hrm.houfei.dao.impl.IMoneyInfoDAO#merge(com.hrm.houfei.po.Moneyinfo)
	 */
	public Moneyinfo merge(Moneyinfo detachedInstance) {
		log.debug("merging Moneyinfo instance");
		try {
			Moneyinfo result = (Moneyinfo) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hrm.houfei.dao.impl.IMoneyInfoDAO#attachDirty(com.hrm.houfei.po.Moneyinfo)
	 */
	public void attachDirty(Moneyinfo instance) {
		log.debug("attaching dirty Moneyinfo instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hrm.houfei.dao.impl.IMoneyInfoDAO#attachClean(com.hrm.houfei.po.Moneyinfo)
	 */
	public void attachClean(Moneyinfo instance) {
		log.debug("attaching clean Moneyinfo instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static IMoneyInfoDAO getFromApplicationContext(ApplicationContext ctx) {
		return (IMoneyInfoDAO) ctx.getBean("MoneyinfoDAO");
	}
}